@extends('template.adminpage')
@section('content')
 
<ol class="breadcrumb">
  <li class="active">Daftar agen</li>
</ol>

<div class="container-black">
  <label style="margin-top:10px"><u>Pencarian</u></label>
  	<form action="{{URL::to('/agens')}}" method="POST">


  		  <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="type" type="radio"  <?php if(Session::get('filter')=="type") echo "checked" ?> ></input>
        </div>
        <div class="col-lg-3">
        <label>Status</label>
        </div>
        <div class="col-lg-3">
           <select  class="form-control" name="typeby" style="height:30px" />
            <?php
              $type = array('all'=>'All','Aktif' => 'Aktif', 'Tidak aktif' => 'Tidak aktif');
              foreach ($type as $key => $val) {
                  if ($key == Session::get('list')) {
                      echo '<option value="' . $key . '" selected>' . $val . '</option>';
                  } else {
                      echo '<option value="' . $key . '">' . $val . '</option>';
                  }
              }
              ?>
          </select>
        </div>
      </div>
      </div>
      <br>


      <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="date" type="radio" <?php if(Session::get('filter')=="date") echo "checked" ?> required ></input>
        </div>
        <div class="col-lg-3">
        <label>Tanggal gabung</label>
        </div>
        <div class="col-lg-3">
          <div class="form-group">
                <div class='input-group date' id='datetimepicker1'>
                    <input type='text' class="form-control" name="datestart" style="height:30px"  value="{{Session::get('datestart')}}" />
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker1').datetimepicker({
                    pickTime: false
                });
            });
        </script>
        </div>
        <div class="col-lg-1">
        <label>s/d</label>
        </div>
         <div class="col-lg-3">
           <div class="form-group">
                <div class='input-group date' id='datetimepicker2'>
                    <input type='text' class="form-control" name="dateend" style="height:30px"  value="{{Session::get('dateend')}}" />
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker2').datetimepicker({
                    pickTime: false
                });
            });
        </script>
        </div>
      </div>
      </div>

    


      <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="keyword" type="radio" <?php if(Session::get('filter')=="keyword") echo "checked" ?> ></input>
        </div>
        <div class="col-lg-3">
        <label>Kata kunci</label>
        </div>
        <div class="col-lg-3">
          <input type="text"  class="form-control" placeholder="Kata kunci" name="keyword" style="height:30px" value="{{Session::get('keyword')}}" /></input>
        </div>
        <div class="col-lg-3 col-md-offset-1">
          <select name="filterby" class="form-control" style="height:30px" />
            <?php
              $type = array('agencode' => 'Kode agen', 'referalcode' => 'Kode referal (sponsor)', 'agenname' => 'Nama agen');
              foreach ($type as $key => $val) {
                  if ($key == Session::get('filterby')) {
                      echo '<option value="' . $key . '" selected>' . $val . '</option>';
                  } else {
                      echo '<option value="' . $key . '">' . $val . '</option>';
                  }
              }
              ?>
          </select>
        </div>
      </div>
      </div>
      <br>
      <div class="row">
      <div class="col-md-9">
        <div class="col-md-3 col-md-offset-4">
             <button class="btn btn-sm btn-dark" type="submit" style="height:30px"><span class="fa fa-search"></span> Tampilkan</button>
        </div>
      </div>
      </div>
        

    </form>
  <label><u>Daftar agen</u></label>
    <br>

    <form action="{{URL::to('/agen/aktif')}}"  method="post" >
    <p><button class="btn btn-sm btn-dark" type="submit" style="height:30px" ><span class="fa fa-circle-o"></span> Aktifkan</button> <button class="btn btn-sm btn-dark" style="height:30px" type="submit" formaction="{{URL::to('/agen/nonaktif')}}" ><span class="fa fa-power-off"></span> Non aktifkan</button></p>
     <div class="table-responsive">
       <?php  
        $limit = 10;
        if(Input::get('page')==0 OR Input::get('page')==1){ 
         $no = 1;
        }
        else{
        $no = ((Input::get('page')-1)*$limit)+1;
        }
       ?>
  	 <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th><input type="checkbox" name="checkall" id="terserah" onclick="check_all('terserah', {{$no}})" ></input></th>
          <th>No</th>
          <th>Kode agen</th>
          <th>Nama agen</th>
          <th>Referal</th>
          <th>No telp / HP</th>
          <th>Tgl join</th>
          <th>Status</th>
          <th>Aksi</th>
        </tr>
      </thead>
      <tbody>
        <tr>
       
       @foreach($dataagen as $agen)
       <?php $refc = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->count();
              $ref = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->first();
              if($refc==0){
                $code = 'Perusahaan';
              }else{
                $code = $ref->agen_code;
              }

              $agenacc = DB::table('sys_account_agen')
                      ->where('account_agen_id',$agen->agen_id)
                      ->count();
                  ?>
         <td ><input type="checkbox" name="{{$agen->agen_id}}" value='1' id="terserah_{{$no}}" ></input></td>
         <td>{{$no}}</td>
         <td>{{$agen->agen_code}}</td>
         <td>{{$agen->member_name}}</td>
         <td>{{$code}}</td>
         <td>{{$agen->member_phone}}</td>
         <td>{{date("d-M-Y",strtotime($agen->member_joindate))}}</td>
         <td>{{$agen->member_status}}</td>
         
          <td style="width:150px"><a data-toggle="modal" data-target="#detail{{$agen->agen_id}}" title="Agen Detail"><button class="btn btn-xs btn-dark" ><span class="fa fa-file"></span></button></a> <a data-toggle="modal" data-target="#ubahpassword{{$agen->agen_id}}" title="Ubah Password Agen"><button class="btn btn-xs btn-dark" <?php if($agenacc=="0") echo "disabled"; ?>><span class="fa fa-key"></span></button></a> <a data-toggle="modal" data-target="#ubahdata{{$agen->agen_id}}" title="Ubah Data Agen"><button class="btn btn-xs btn-dark"><span class="fa fa-edit"></span></button></a> <button type="reset" onclick="window.open('{{URL::to('/agenlogin/'.$agen->agen_id)}}', '_blank');" <?php if((Session::get('agenlogin')==$agen->agen_id) AND (Session::get('agenlogin')<>"")) echo 'class="btn btn-xs btn-danger" title="Agen login"'; ?> title="Login agen" class="btn btn-xs btn-dark" <?php if($agen->member_status<>"Aktif") echo "disabled"; ?>  ><span class="fa fa-sign-in"></span></button> <button class="btn btn-xs btn-dark" title="Bonus agen" <?php if($agen->agen_id=="0") echo "disabled"; ?> formaction="{{URL::to('agen/bonus/'.$agen->agen_id)}}" ><span class="fa fa-money"></span></button> </td>
        <?php $no++; ?>
      </tr>
      @endforeach
      </tbody>


    </table>
  <div class="text-right"><?php echo $dataagen->links(); ?></div>
  </div>
  </form>

     @foreach($dataagen as $agen)
              <div class="modal fade" id="ubahpassword{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:25px">Ganti password</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/agen/editpassword/'.$agen->agen_id,
                                    'method' => 'POST'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Password baru <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password baru" name="password" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Ulangi password baru <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password lagi" name="password_confirmation" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5 col-lg-offset-5">
                                 <font color="red">* Data tidak boleh kosong</font><br>
                                  </div>
                                  </div>

                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-sm btn-dark"><span class="fa fa-floppy-o"></span> Simpan</button>{{Form::close()}} <button class="btn btn-sm btn-dark" style="margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>

                <div class="modal fade" id="login{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg" style="width:35%">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:25px">Harap masukan password untuk login</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/agen/login/'.$agen->agen_id,
                                    'method' => 'POST'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  
                                  <div class="row">
                                  <div class="col-lg-3">
                                  <label>Password<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-7">
                                    <input type="password" placeholder="Password" name="password" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-7 col-lg-offset-3">
                                 <font color="red">* Data tidak boleh kosong</font><br>
                                  </div>
                                  </div>

                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-sm btn-dark"><span class="fa fa-sign-in"></span> Login</button>{{Form::close()}} <button class="btn btn-sm btn-dark" style="margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>

                <div class="modal fade" id="ubahdata{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:5px">Ganti data profil</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/agen/editprofile/'.$agen->agen_id,
                                    'method' => 'POST'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Tanggal join</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text"  class="form-control" style="width:270px;height:30px" value='{{date("d-M-Y",strtotime($agen->member_joindate))}}' disabled /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Referal agen (Kode)</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text"  class="form-control" style="width:270px;height:30px"  value="{{$agen->agen_sponsor_id}}" disabled  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kode agen</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text"  class="form-control" style="width:270px;height:30px"  value="{{$agen->agen_code}}" disabled /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama agen <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text"  class="form-control" name="member_name" style="width:270px;height:30px" value="{{$agen->member_name}}" required  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <textarea  class="form-control" name="member_address" style="width:270px;height:70px" required  />{{$agen->member_address}}</textarea>
                                  </div>
                                  </div>
                                 
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kota / Kabupaten <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <select  class="form-control" name="member_regional_id" style="width:270px;height:30px" required />
                                    <?php 
                                    foreach($regional as $kota){
                                      if($kota->regional_id==$agen->member_regional_id){
                                        echo '<option value="'.$kota->regional_id.'" selected>'.$kota->regional_name.'</option>';
                                      }else{
                                        echo '<option value="'.$kota->regional_id.'">'.$kota->regional_name.'</option>';
                                      }
                                    }
                                    ?>
                                    </select>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Propinsi <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <select  class="form-control" name="member_provinsi_id" style="width:270px;height:30px" required />
                                    <?php 
                                    foreach($provinsi as $kota){
                                      if($kota->provinsi_id==$agen->member_provinsi_id){
                                        echo '<option value="'.$kota->provinsi_id.'" selected>'.$kota->provinsi_name.'</option>';
                                      }else{
                                        echo '<option value="'.$kota->provinsi_id.'">'.$kota->provinsi_name.'</option>';
                                      }
                                    }
                                    ?>
                                    </select>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nomor telepon / HP<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="phone"  class="form-control" name="member_phone" style="width:270px;height:30px" value="{{$agen->member_phone}}" required /></input>
                                  </div>
                                  </div>

                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat email<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="email"  class="form-control" name="member_email" style="width:270px;height:30px" value="{{$agen->member_email}}" required <?php if($agen->member_status=="Aktif") echo "disabled"; ?> /></input>
                                  </div>
                                  </div>
                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">

                    <button type="submit" class="btn btn-sm btn-dark" ><span class="fa fa-floppy-o"></span> Simpan</button>{{Form::close()}} <button class="btn btn-sm btn-dark" style=" margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>




                <div class="modal fade" id="detail{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:5px">Agen detail</label></h4>
                    </div>
                    <div align="left">
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Tanggal join</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{date("d-M-Y",strtotime($agen->member_joindate))}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Referal agen (Kode)</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label><?php if($agen->agen_sponsor_id=="")echo "-"; else echo $agen->agen_sponsor_id; ?></label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kode agen</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->agen_code}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama agen <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_name}}</label>                                  
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_address}}</label>
                                  </div>
                                  </div>
                                 
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kota / Kabupaten <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->regional_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Propinsi <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->provinsi_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nomor telepon / HP<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_phone}}</label>                
                                  </div>
                                  </div>

                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat email<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_email}}</label>
                                  </div>
                                  </div>
                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">

                    <button class="btn btn-sm btn-dark" style=" margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>
@endforeach

</div>


@stop
@stop